package com.liveinstars.im.domain.manager.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liveinstars.im.domain.dao.mapper.CandyBoxMapper;
import com.liveinstars.im.domain.dao.model.CandyBox;
import com.liveinstars.im.domain.manager.CandyBoxManager;
import com.onepiece.shipelves.common.constant.Constant;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import com.onepiece.shipelves.common.exception.DatabaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 糖果盒表 服务实现类
 * </p>
 *
 * @author 8btc
 * @since 2020-03-24
 */
@Service
public class CandyBoxManagerImpl extends ServiceImpl<CandyBoxMapper, CandyBox> implements CandyBoxManager {

    private final static Logger logger = LoggerFactory.getLogger(CandyBoxManagerImpl.class);

    @Override
    public void add(CandyBox candyBox) {
        candyBox.setStatus(Constant.NO);
        candyBox.setState(Constant.STATE_VALID);
        try {
            this.save(candyBox);
        }catch (Exception e) {
            logger.error("添加糖果盒异常异常：{}", e.getMessage() , e);
            throw new DatabaseException(SystemExceptionEnum.MYSQL_OPERATING_ERROR);
        }
    }
}
